package com.jsoft.model;

import com.jsoft.dto.UserDto;
import com.jsoft.model.core.BaseDao;

import javax.persistence.*;
import java.util.List;

/**
 * Date: 15.08.13
 * Time: 14:42
 */

@Entity
@Table(name = "users")
public class UserDao extends BaseDao {
    @Column(name = "login")
    private String login;
    @Column(name = "password")
    private String password;
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "person_id", nullable = false)
    private PersonDao person;
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "sectors_users",
            joinColumns = @JoinColumn(name = "user_id"),
            inverseJoinColumns = @JoinColumn(name = "sector_id")
    )
    private List<SectorDao> sectorList;
    @Column(name = "card_number")
    private String cardNumber;

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public PersonDao getPerson() {
        return person;
    }

    public void setPerson(PersonDao person) {
        this.person = person;
    }

    public List<SectorDao> getSectorList() {
        return sectorList;
    }

    public void setSectorList(List<SectorDao> sectorList) {
        this.sectorList = sectorList;
    }

    public String getCardNumber() {
        return cardNumber;
    }

    public void setCardNumber(String cardNumber) {
        this.cardNumber = cardNumber;
    }

    public UserDto wrapUserDto() {
        UserDto dto = new UserDto();
        dto.setLogin(this.getLogin());
        dto.setPassword(this.getPassword());
        dto.setSig(this.getLogin() + this.getPassword());
        return dto;
    }

    public UserDao wrapUserDao(UserDto dto) {
        UserDao dao = new UserDao();
        dao.setLogin(dto.getLogin());
        dao.setPassword(dto.getPassword());
        return dao;
    }
}
